
#pragma warning ( disable : 4786 )

#include "stdafx.h"
#include "TestPDMSClassRegister.h"
#include "PDMSClassRegister.h"

using namespace PDMS::PDMSFrame;

CPPUNIT_TEST_SUITE_REGISTRATION( TestPDMSClassRegister );


TestPDMSClassRegister::TestPDMSClassRegister()
{
}


TestPDMSClassRegister::~TestPDMSClassRegister()
{
}

void TestPDMSClassRegister::TestInstance()
{
	PDMSClassRegister* pReg = PDMSClassRegister::Instance();
	CPPUNIT_ASSERT( pReg );
}

#include "Tree.h"

class TestTreeClass : public Tree
{
	UE_PDMSCLASS_DEFINE( TestTreeClass );

public:
	TestTreeClass(){
	}
	virtual ~TestTreeClass(){
	}
	virtual BOOL IsLegalParent( PDMS::PDMSFrame::Tree* pParent ){
		return TRUE;
	}
	virtual Persistable* Clone(){
		return NULL;
	}
};

UE_PDMSCLASS_IMPLEMENT( TestTreeClass, Tree, _T("TTre") );

void TestPDMSClassRegister::TestFindInfo()
{
	PDMSClassRegisterInfo* pInfo = NULL;

	CPPUNIT_ASSERT( PDMSClassRegister::Instance()
		->FindInfo( UE_PDMSCLASS_REGKEY( TestTreeClass ), pInfo ) );
	
	CPPUNIT_ASSERT( !PDMSClassRegister::Instance()
		->FindInfo( UE_PDMSCLASS_REGKEY( TestTreeClass1 ), pInfo ) );
}

void TestPDMSClassRegister::TestHasClass()
{
	CPPUNIT_ASSERT( PDMSClassRegister::Instance()
		->HasClass( UE_PDMSCLASS_REGKEY( TestTreeClass ) ) );
	
	CPPUNIT_ASSERT( !PDMSClassRegister::Instance()
		->HasClass( UE_PDMSCLASS_REGKEY( TestTreeClass1 ) ) );
}

void TestPDMSClassRegister::TestCreateObject()
{
	Tree* pTree = PDMSClassRegister::Instance()
		->CreateObject( UE_PDMSCLASS_REGKEY( TestTreeClass ) );
	CPPUNIT_ASSERT( pTree );
	CPPUNIT_ASSERT( pTree->IsKindOf( UE_RUNTIME_CLASS( TestTreeClass ) ) );
	CPPUNIT_ASSERT( pTree->ClassID() == _T("TTre") );
	delete pTree;
	pTree = NULL;

	pTree = PDMSClassRegister::Instance()
		->CreateObject( UE_PDMSCLASS_REGKEY( TestTreeClass1 ) );
	CPPUNIT_ASSERT( pTree == NULL );
}